﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for TransposeMainFigures
/// </summary>
public class ConvertMainFigures
{
	public ConvertMainFigures()
	{
		//
		// TODO: Add constructor logic here
		//
	}



  public static DataTable ConvertYears(DataTable dataTable)
  {
    DataTable newDataTable = new DataTable();
    newDataTable.Columns.Add("Regnskabsår");
    //Get all the rows and change into columns
    for (int row = 0; row < dataTable.Rows.Count; row++)
    {
      newDataTable.Columns.Add(dataTable.Rows[row][0].ToString()); //Add column titles
    }
    return newDataTable;
  }

  public static DataTable ConvertIncomeStatement(DataTable dataTable)
  {
    DataTable newDataTable = new DataTable();
    newDataTable.Columns.Add(" ");
    //Get all the rows and change into columns
    for (int row = 0; row < dataTable.Rows.Count; row++)
    {
      newDataTable.Columns.Add(row.ToString()); //Add column titles
    }

    DataRow dr;
    //get all the columns and make it as rows
    for (int column = 1; column < 4; column++) //column 1-3 in datatable
    {
      dr = newDataTable.NewRow();
      string keyfigureName = dataTable.Columns[column].ToString();
      dr[0] = Dictionary.Translate(keyfigureName);

      for (int row = 1; row <= dataTable.Rows.Count; row++)
      {
        dr[row] = ConvertKeyFigureDigit.Convert(dataTable.Rows[row - 1][column].ToString(), keyfigureName);
      }
      newDataTable.Rows.Add(dr);
    }
    return newDataTable;
  }

  public static DataTable ConvertAssets(DataTable dataTable)
  {
    DataTable newDataTable = new DataTable();
    newDataTable.Columns.Add(" ");
    //Get all the rows and change into columns
    for (int row = 0; row < dataTable.Rows.Count; row++)
    {
      newDataTable.Columns.Add(row.ToString()); //Add column titles
    }

    DataRow dr;
    //get all the columns and make it as rows
    for (int column = 4; column < 7; column++) //column 4-6 in datatable
    {
      dr = newDataTable.NewRow();
      string keyfigureName = dataTable.Columns[column].ToString();
      dr[0] = Dictionary.Translate(keyfigureName);

      for (int row = 1; row <= dataTable.Rows.Count; row++)
      {
        dr[row] = ConvertKeyFigureDigit.Convert(dataTable.Rows[row - 1][column].ToString(), keyfigureName);
      }
      newDataTable.Rows.Add(dr);
    }
    return newDataTable;
  }

  public static DataTable ConvertLiabilities(DataTable dataTable)
  {
    DataTable newDataTable = new DataTable();
    newDataTable.Columns.Add(" ");
    //Get all the rows and change into columns
    for (int row = 0; row < dataTable.Rows.Count; row++)
    {
      newDataTable.Columns.Add(row.ToString()); //Add column titles
    }

    DataRow dr;
    //get all the columns and make it as rows
    for (int column = 7; column < 11; column++) //column 7-10 in datatable
    {
      dr = newDataTable.NewRow();
      string keyfigureName = dataTable.Columns[column].ToString();
      dr[0] = Dictionary.Translate(keyfigureName);

      for (int row = 1; row <= dataTable.Rows.Count; row++)
      {
        dr[row] = ConvertKeyFigureDigit.Convert(dataTable.Rows[row - 1][column].ToString(), keyfigureName);
      }
      newDataTable.Rows.Add(dr);
    }
    return newDataTable;
  }

  public static DataTable ConvertOtherInfo(DataTable dataTable)
  {
    DataTable newDataTable = new DataTable();
    newDataTable.Columns.Add(" ");
    //Get all the rows and change into columns
    for (int row = 0; row < dataTable.Rows.Count; row++)
    {
      newDataTable.Columns.Add(row.ToString()); //Add column titles
    }

    DataRow dr;
    //get all the columns and make it as rows
    for (int column = 11; column < 15; column++) //column 11-14 in datatable
    {
      dr = newDataTable.NewRow();
      string keyfigureName = dataTable.Columns[column].ToString();
      dr[0] = Dictionary.Translate(keyfigureName);

      for (int row = 1; row <= dataTable.Rows.Count; row++)
      {
        dr[row] = ConvertKeyFigureDigit.Convert(dataTable.Rows[row - 1][column].ToString(), keyfigureName);
      }
      newDataTable.Rows.Add(dr);
    }
    return newDataTable;
  }
}